<?
$title = "Edit category";
$pageid = "5";
$accessid = "a00";

require("required/dbconnect.php");
require("required/function.php");

if (isset($_GET['btnsubmit'])) {
    $zone_id = $_GET['zone_id'];
    $zone_q = " and zone_id='$zone_id'";
    $zone_q_2 = " and a.id='$zone_id'";
} else {
    $zone_id = "";
    $zone_q = "";
    $zone_q_2 = "";
}

require("required/header.php");

checkAccess("allow_shipping_management", 1);

$id = $_GET['id'];

$get_info = mysql_query("select * from os_shipping_company where id='$id'");

if (mysql_num_rows($get_info) == 0) {
    echo "No record found!!";
} else {


    $a = mysql_fetch_array($get_info, MYSQL_ASSOC);
    if ($a['status'] == 0) {
        $slt0 = "selected";
        $slt1 = "";
    } else {
        $slt0 = "";
        $slt1 = "selected";
    }
    ?>
    <script src="required/js/jquery-1.4.2.js"></script>
    <script src="required/js/common_javascript.js"></script>
    <?
    if (!empty($_GET['action'])) {
        $updated = $_GET['action'];

        switch ($updated) {
            case 1:
                $msg = "<div class='dw_success'>Record Updated</div>";
                break;
            case 3:
                $msg = "<div class='dw_success'>Stock Updated</div>";
                break;
            case 4:
                $msg = "<div class='dw_success'>Shipping Rate Added</div>";
                break;
            case 5:
                $msg = "<div class='dw_success'>Shipping Rate Updated</div>";
                break;
            default:
                $msg = "unknown";
                break;
        }
        echo "<script>displayMsg('divMsg')</script>";
    } else {
        $msg = "";
    }
    ?>

    <table width="95%" cellpadding="2" cellspacing="1">
        <td valign="top">
            <table width="700">
                <tr>
                    <td colspan="4"><font class="title">Shipping Company</font><br />
                        <div id="divMsg"><?= $msg ?></div>
                    </td>
                </tr>
                <input type="hidden" value="<?= $id ?>" name="id">
                <tr>
                    <td width="100">Company Name</td>
                    <td width="5">:</td>
                    <td><?= $a['company_name'] ?></td>
                </tr>


                <tr>
                    <td colspan="3" align="center"><br>
                        <input type="button" value="Import Data" onclick="window.open('shipping_import.php?id=<?= $id ?>','_self')">
                        <input type="button" value="Back" class="button" onclick="window.open('shipping_view_all.php','_self')">
                        <br>
                        <br></td>
                </tr>
                <tr>
                    <td colspan="3">
                        <br />

                        <table width="100%" class="solidborder">
                            <tr class="table_header">
                                <td>No.</td><td>Zone</td><Td>Total Rate Added</Td><td>Total Country Added</td><Td>Upload Group</td>
                            </tr>
                            <?
                            $get_zone = mysql_query("select * from os_shipping_zone where courier_id='$id' order by zone_name asc") or die(mysql_error());

                            if (mysql_num_rows($get_zone) == 0) {
                                ?>
                                <tr>
                                    <Td colspan="6" align="center"> - No Record -</Td>
                                </tr>
                                <?
                            } else {
                                $no = 1;

                                while ($r = mysql_fetch_array($get_zone, MYSQL_ASSOC)) {
                                    if ($no % 2 == 0) {
                                        $class1 = "table_item_even";
                                        $class2 = "table_item_odd";
                                    } else {
                                        $class1 = "table_item_odd";
                                        $class2 = "table_item_even";
                                    }

                                    $get_total_rate = mysql_query("select count(*) as result from os_shipping_zone_rate where zone_id=" . $r['id']) or die(mysql_error());
                                    $get_total_country = mysql_query("select count(*) as result from os_shipping_zone_country where zone_id=" . $r['id']) or die(mysql_error());
                                    ?>	
                                    <tr height="20" valign="top" class="<?= $class1 ?>"  onmouseover="this.className='table_item_mouseover'" 
                                        onmouseout="this.className='<?= $class1 ?>'">
                                        <Td><?= $no ?></Td>
                                        <td align="center"><?= $r['zone_name'] ?></td>
                                        <td align="center"><?= mysql_result($get_total_rate, 0, "result") ?> 
                                            <a href="shipping_zone_rate.php?id=<?= $id ?>&zone_id=<?= $r['id'] ?>">View</a> 


                                        </td>
                                        <td align="center"><?= mysql_result($get_total_country, 0, "result") ?> 
                                            <a href="shipping_zone_country.php?id=<?= $id ?>&zone_id=<?= $r['id'] ?>">View</a> 

                                        </td>
                                        <Td><?= getDataById("os_shipping_upload_group", "group_name", "id", $r['group_id']) ?></td>

                                    </tr>
                                    <?
                                    $no++;
                                }
                            }
                            ?>
                        </table>
                    </td>
                </tr>

            </table></td>
    </table>
<? } require("required/footer.php"); ?>
